package 力扣.树.后序遍历;

import java.util.LinkedList;
import java.util.List;
import java.util.Queue;

public class test {
    class Node {
        public int val;
        public List<Node> children;
        public Node() {}
        public Node(int _val) {
            val = _val;
        }
        public Node(int _val, List<Node> _children) {
            val = _val;
            children = _children;
        }
    }
    public List<Integer> postorder(Node root) {
        Queue<Node> q = new LinkedList<>();
        LinkedList<Integer> ans = new LinkedList<>();
        if(root == null) return ans;
        q.add(root);
        ans.add(root.val);
        while(!q.isEmpty()){
            Node father = q.poll();
            for(Node son : father.children){
                ans.add(ans.indexOf(father.val),son.val);
                q.add(son);
            }
        }
        return ans;
    }
}
